package com.uinnova.springboot.mongodb;

import com.uinnova.springboot.mongodb.dao.UserMongo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private UserMongo userMongo;

    @GetMapping(value = "/jail/user/save")
    public void saveUsers(){
        User user1 = new User("1","wanggang1","1");
        User user2 = new User("2","wanggang2","2");
        User user3 = new User("3","wanggang3","3");
        User user4 = new User("4","wanggang4","4");
        userService.saveUser(user1);
        userService.saveUser(user2);
        userService.saveUser(user3);
        userService.saveUser(user4);
        System.out.println("用户信息录入完成");
    }

    @GetMapping(value = "/jail/user/delete/{id}")
    public void deleteUser(@PathVariable String id){
        userService.deleteUser(id);
        System.out.println("用户已经被删除");
    }

    @GetMapping(value = "/jail/user/update/{name}")
    public void updateUser(@PathVariable String name){
        User user = userService.queryByName(name);
        user.setName("wanggangxiugai");
        user.setAge("22");
        userService.updateUser(user);
        System.out.println("用户已经成功修改");
    }

    @GetMapping(value = "jail/user/query/{name}")
    public User queryByName(@PathVariable String name){
        return userService.queryByName(name);
    }






}
